package com.example.demo.socket;

import com.example.demo.util.StringUtil;

import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

public class TCPClient {
    public static void main(String[] args){
        try{
            Socket socket = new Socket("localhost",65000);

            OutputStream outputStream = socket.getOutputStream();

            String message = "hello word";
            outputStream.write(message.getBytes());

            InputStream inputStream = socket.getInputStream();

            int ch = 0;
            byte[] bytes = new byte[1024];
            ch = inputStream.read(bytes);
            String result = new String(bytes,0,ch);
            //String result = StringUtil.readFileContent(inputStream,"utf-8");
            System.out.println("result:"+result);

            inputStream.close();
            outputStream.close();
            socket.close();

        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
